/**
 * @file ConfirmDialog.vue
 * @description 通用确认对话框组件
 * @created 2024-06-25
 */

<template>
  <div class="confirm-overlay" @click.self="handleCancel">
    <div class="confirm-container">
      <div class="confirm-header">
        <h3>{{ title }}</h3>
      </div>
      
      <div class="confirm-body">
        <p>{{ message }}</p>
      </div>
      
      <div class="confirm-footer">
        <button class="cancel-btn" @click="handleCancel">{{ cancelText }}</button>
        <button class="confirm-btn" @click="handleConfirm">{{ confirmText }}</button>
      </div>
    </div>
  </div>
</template>

<script setup>
// 接收参数
const props = defineProps({
  title: {
    type: String,
    default: '确认操作'
  },
  message: {
    type: String,
    default: '确定要执行此操作吗？'
  },
  confirmText: {
    type: String,
    default: '确认'
  },
  cancelText: {
    type: String,
    default: '取消'
  }
});

// 定义事件
const emit = defineEmits(['confirm', 'cancel']);

// 确认按钮处理
const handleConfirm = () => {
  emit('confirm');
};

// 取消按钮处理
const handleCancel = () => {
  emit('cancel');
};
</script>

<style scoped>
.confirm-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
}

.confirm-container {
  background-color: white;
  border-radius: 8px;
  width: 400px;
  max-width: 90%;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.confirm-header {
  padding: 15px 20px;
  border-bottom: 1px solid #eaeaea;
}

.confirm-header h3 {
  margin: 0;
  font-size: 18px;
  color: #333;
}

.confirm-body {
  padding: 20px;
}

.confirm-body p {
  margin: 0;
  font-size: 14px;
  color: #666;
}

.confirm-footer {
  display: flex;
  justify-content: flex-end;
  padding: 15px 20px;
  border-top: 1px solid #eaeaea;
  gap: 10px;
}

.cancel-btn {
  padding: 8px 16px;
  background-color: #f5f5f5;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  cursor: pointer;
  color: #666;
}

.confirm-btn {
  padding: 8px 16px;
  background-color: #ff4d4f;
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
}

.confirm-btn:hover {
  background-color: #ff7875;
}

.cancel-btn:hover {
  background-color: #eaeaea;
}
</style> 